package com.jtjrenren.android.taxi.passenger.core.setting.config;

import android.content.Intent;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.jtjrenren.android.taxi.passenger.Constants;
import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseActivity;
import com.jtjrenren.android.taxi.passenger.core.setting.address.SetAddressActivity;
import com.library.utils.SpUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/1/26.
 */
public class SettingActivity extends BaseActivity {
    @BindView(R.id.setting_sound_toggle)
    ToggleButton tg_sound;
    @BindView(R.id.setting_gps_toggle)
    ToggleButton tg_gps;
    @BindView(R.id.setting_orderfinish_toggle)
    ToggleButton tg_ordernotfinish;
    @BindView(R.id.title)
    TextView tv_title;

    private boolean voiceSwitch, gpsCheckSwitch, orderNotFinishSwitch;

    @Override
    public int getLayoutId() {
        return R.layout.aty_settting_main;
    }

    @Override
    public void init() {
        tv_title.setText("设置");
        initData();

        setListeners();
    }

    private void initData() {
        voiceSwitch = (boolean) SpUtils.getParam(SettingActivity.this, Constants.SP_SETTING_VOICE_SWITCH, false);
        tg_sound.setChecked(voiceSwitch);

        gpsCheckSwitch = (boolean) SpUtils.getParam(SettingActivity.this, Constants.SP_SETTING_GPS_SWITCH, true);
        tg_gps.setChecked(gpsCheckSwitch);

        orderNotFinishSwitch = (boolean) SpUtils.getParam(SettingActivity.this, Constants.SP_SETTING_CHECKNOTFINISHORDER_SWITCH, true);
        tg_ordernotfinish.setChecked(orderNotFinishSwitch);
    }

    private void setListeners() {
        tg_sound.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked == voiceSwitch)
                    SpUtils.setParam(SettingActivity.this, Constants.SP_SETTING_VOICE_SWITCH, isChecked);
            }
        });

        tg_gps.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked == gpsCheckSwitch)
                    SpUtils.setParam(SettingActivity.this, Constants.SP_SETTING_GPS_SWITCH, isChecked);
            }
        });

        tg_ordernotfinish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked == orderNotFinishSwitch)
                    SpUtils.setParam(SettingActivity.this, Constants.SP_SETTING_CHECKNOTFINISHORDER_SWITCH, isChecked);
            }
        });
    }

    @OnClick(R.id.title_left)
    public void clickBack(){
        finish();
    }

    @OnClick(R.id.setting_dizhibu)
    public void clickDzb() {
        Intent intent = new Intent(this, SetAddressActivity.class);
        startActivity(intent);
    }
}
